<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <title>明日新闻</title>
    <link rel="stylesheet" type="text/css" href="../style/css/front/public.css">
    <style>
        #commentDiv {
            border: solid black 1px;
            width: 650px;
            height: 300px;
        }
        #addCommentId{
            border:  solid black 1px;
            width: 400px;
            height: 30px;
        }

    </style>
    <script src="../style/js/jquery-1.8.3.js" type="text/javascript"></script>
    <script src="../style/js/ajaxfileupload.js"></script>
    <script type="text/javascript">
        $(function () {
            var id = location.search.split("=")[1];
            console.log(id);
            $.get("../webmsg/newid", {id: id}, function (res9) {
                if (res9.code == 201) {
                    alert("失败")
                } else if (res9.code == 500) {
                    alert("服务器忙");
                } else {
                    console.log(res9.data);
                    var userId = window.sessionStorage.getItem("userId");
                    if (res9.data.newsId > 0 && userId != null) {
                        $("input[name='collect']").attr("checked", true);
                        var n = document.getElementById("collectimg")
                        n.src = "../style/img/front/shoucang1.png"
                    }
                    $("#type").html("<p style='text-align:center'><span style='font-size:36px'>" + res9.data.title + "</span></p>")
                    $("#newstitle").html("<p>" + res9.data.content + "</p>")
                }
            }, "json");


            $.get("../webmsg/webmsg", function (res) {
                if (res.code == 201) {
                    alert("失败")
                } else if (res.code == 500) {
                    alert("服务器忙");
                } else {
                    $("#logo1").html("<img src='" + "http://127.0.0.1:8080/tomorrowNewsFiles/logo/" + res.data.logoName + "' width='200' height='90'/>");
                    var str = "";
                    str += "<p>" + '© ' + (new Date(res.data.operateTime).getFullYear()) + "&nbsp" + res.data.webName + "&nbsp" + '备案号' + "&nbsp" + res.data.recordNum + '号' + "</p>"
                    str += "<p>" + '联系电话: ' + res.data.phone + "</p>";
                    str += "<p>" + '公司名称: ' + res.data.companyName + "&nbsp" + "&nbsp" + "&nbsp" + "<a href='../user/login.html'>管理员登录</a>" + "&nbsp" + "&nbsp" + "<a href='upload.html'>更换logo</a>" + "</p>";
                }
                $("#webmsg").html(str);
                var filename = window.sessionStorage.getItem("filename");
                var id = window.sessionStorage.getItem("id");
            }, "json");


//新闻类型
            $.get("../webmsg/newstype", function (res1) {
                if (res1.code == 201) {
                    alert("失败")
                } else if (res1.code == 500) {
                    alert("服务器忙");
                } else {
                    var str = "";
                    for (i = 0; i < res1.data.length; i++) {
                        str += "<li><a href='javaScript:void(0)' class='sf-with-ul' onclick='selecttype(" + res1.data[i].id + ")'>" + res1.data[i].name + "</a></li>";
                    }
                    $("#newstype").html(str);
                }
            }, "json");

            //广告位显示
            //新闻类型
            $.get("../webmsg/admsg", function (res8) {
                if (res8.code == 201) {
                    alert("失败")
                } else if (res8.code == 500) {
                    alert("服务器忙");
                } else {
                    console.log(res8)
                    for (i = 0; i < res8.data.length; i++) {
                        if (res8.data[i].position == 1) {
                            $("#admsg1").html("<img src='" + "http://127.0.0.1:8080/tomorrowNewsFiles/ad/" + res8.data[i].name + "' width='800' height='90'/>")
                        } else if (res8.data[i].position == 2) {
                            $("#admsg2").html("<img src='" + "http://127.0.0.1:8080/tomorrowNewsFiles/ad/" + res8.data[i].name + "' width='800' height='90'/>")
                        } else if (res8.data[i].position == 3) {
                            $("#admsg3").html("<img src='" + "http://127.0.0.1:8080/tomorrowNewsFiles/ad/" + res8.data[i].name + "' width='800' height='90'/>")
                        } else if (res8.data[i].position == 4) {
                            $("#admsg4").html("<img src='" + "http://127.0.0.1:8080/tomorrowNewsFiles/ad/" + res8.data[i].name + "' width='800' height='90'/>")
                        } else {
                            alert("参数错误")
                        }
                    }
                }
            }, "json");

            //推荐文章
            $.get("../webmsg/recommend", function (res11) {
                if (res11.code == 201) {
                    alert("失败")
                } else if (res11.code == 500) {
                    alert("服务器忙");
                } else {
                    console.log(res11)
                    var str = "";
                    for (i = 0; i < res11.data.length; i++) {
                        str += "<li><div class=\"artl\"><a href='javaScript:void(0)' onclick='newscont(" + res11.data[i].id + ")'>\n" +
                            "<p>" + res11.data[i].title + "</p></a>\n" +
                            "\t\t \t<label>" + res11.data[i].publishTime + "</label>\n" +
                            "\t\t \t\t\t\t\t\t</div><div class=\"artr\">\n" +
                            "\t\t \t\t\t\t\t\t\t<a href=\"\" target=\"_blank\" id=\"admsg5\">\n" + "<img src='" + "http://127.0.0.1:8080/tomorrowNewsFiles/ad/" + res11.data[i].coverPicture + "' width='800' height='90'/>" +
                            "\t\t \t\t\t\t\t\t\t</a></div></li>   "
                    }
                    $("#recommend").html(str);

                }
            }, "json");


            //点击最多
            $.get("../webmsg/click", function (res12) {
                if (res12.code == 201) {
                    alert("失败")
                } else if (res12.code == 500) {
                    alert("服务器忙");
                } else {
                    console.log(res12)
                    var str = "";
                    for (i = 0; i < res12.data.length; i++) {
                        str += "\t<li><div class=\"artl\"><a href='javaScript:void(0)' onclick='newscont(" + res12.data[i].id + ")'>\n" +
                            "\t\t\t\t\t\t\t\t<p>" + res12.data[i].title + "</p></a>\n" +
                            "\t\t\t\t\t\t\t<label>" + res12.data[i].publishTime + "</label>\n" +
                            "\t\t\t\t\t\t</div><div class=\"artr\">\n" +
                            "\t\t\t\t\t\t\t<a href=\"\" target=\"_blank\"><img src='" + "http://127.0.0.1:8080/tomorrowNewsFiles/ad/" + res12.data[i].coverPicture + "' width='800' height='90'/></a></div></li>"
                    }
                    $("#click").html(str);

                }
            }, "json");


            //友情链接
            $.get("../webmsg/links", function (res2) {
                if (res2.code == 201) {
                    alert("失败")
                } else if (res2.code == 500) {
                    alert("服务器忙");
                } else {
                    var str = "";
                    for (i = 0; i < res2.data.length; i++) {
                        str += "<a href='" + "https://www." + res2.data[i].linkUrl + "'>" + res2.data[i].linkName + "</a>"
                    }
                    $("#link").html(str)

                }
            }, "json");


            //显示改文章评论
            $.get("../comment/getCommentByNewsId", {newsId: id}, function (res) {
                if (res.code === 500 || res.code === 202) {
                    alert(res.msg)
                } else {
                    var str = "";
                    for (let i = 0; i < res.data.length; i++) {
                        if (res.data[i].pid === 0 && res.data[i].state === 1) {
                            str += "<span><b>" + res.data[i].commenterNickName + "</b></span>\t\t"
                            str += "<span><b>" + res.data[i].time + "</b></span>\t\t"
                            str += "<p>" + res.data[i].content + "</p><br>"
                        }
                    }
                    $("#commentDiv").html(str);
                }
            })
        })

        //文章内容
        function selecttype(id) {
            if (id == 1) {
                $.get("../webmsg/newnewstypeid", function (res7) {
                    if (res7.code == 201) {
                        alert("失败")
                    } else if (res7.code == 500) {
                        alert("服务器忙");
                    } else {
                        $("#type").html("最新推荐")
                        var str = "";
                        for (i = 0; i < res7.data.length; i++) {
                            str += "<div class=\"lista\">"
                            str += "<h3>";
                            str += "<a href='javaScript:void(0)' onclick='newscont(" + res7.data[i].id + ")' id='title'>" + res7.data[i].title + "</a>"
                            str += "</h3>";
                            str += "<div class=\"pov\"><div class=\"sview\"><div class=\"sviewl\"><div class=\"tittop\">";
                            str += "<b>" + res7.data[i].publishTime + "</b>"
                            str += " </div><div class=\"art_summary\">";
                            str += "<p>" + res7.data[i].summary + "</p>";
                            str += "</div><div class=\"footbar\"><i class=\"footbar-category\"><a href=\"\">互联网</a></i><i class=\"footbar-like\"><a href=\"javascript:;\">点击量" + res7.data[i].clickNum + "</a></i></div></div><div class=\"sviewr\">";
                            str += "</div></div></div>";
                            str += "</div>"
                        }
                        $("#newstitle").html(str);
                    }
                }, "json");
            } else {
                $.get("../webmsg/newstypeid", {id: id}, function (res5) {
                    console.log(id)
                    if (res5.code == 201) {
                        alert("失败")
                    } else if (res5.code == 500) {
                        alert("服务器忙");
                    } else {
                        $("#type").html(res5.data[0].name)
                        var str = "";
                        for (i = 0; i < res5.data.length; i++) {
                            str += "<div class=\"lista\">"
                            str += "<h3>";
                            str += "<a href='javaScript:void(0)' onclick='newscont(" + res5.data[i].id + ")' id='title'>" + res5.data[i].title + "</a>"
                            str += "</h3>";
                            str += "<div class=\"pov\"><div class=\"sview\"><div class=\"sviewl\"><div class=\"tittop\">";
                            str += "<b>" + res5.data[i].publishTime + "</b>"
                            str += " </div><div class=\"art_summary\">";
                            str += "<p>" + res5.data[i].summary + "</p>";
                            str += "</div><div class=\"footbar\"><i class=\"footbar-category\"><a href=\"\">互联网</a></i><i class=\"footbar-like\"><a href=\"javascript:;\">点击量" + res5.data[i].clickNum + "</a></i></div></div><div class=\"sviewr\">";
                            str += "</div></div></div>";
                            str += "</div>"
                        }
                        $("#newstitle").html(str);
                    }
                }, "json");
            }
        }

        //搜索
        function search() {
            $.get("../webmsg/search", $("#searchform").serialize(), function (res6) {
                console.log(res6.data)
                if (res6.code == 200) {
                    console.log(res6.data)
                    alert("登录成功")
                    var str = "";
                    for (i = 0; i < res6.data.length; i++) {
                        str += "<div class=\"lista\">"
                        str += "<h3>";
                        str += "<a href='javaScript:void(0)' onclick='newscont(" + res6.data[i].id + ")'  id='title'>" + res6.data[i].title + "</a>"
                        str += "</h3>";
                        str += "<div class=\"pov\"><div class=\"sview\"><div class=\"sviewl\"><div class=\"tittop\">";
                        str += "<b>" + res6.data[i].publishTime + "</b>"
                        str += " </div><div class=\"art_summary\">";
                        str += "<p>" + res6.data[i].summary + "</p>";
                        str += "</div><div class=\"footbar\"><i class=\"footbar-category\"><a href=\"\">互联网</a></i><i class=\"footbar-like\"><a href=\"javascript:;\">点击量" + res6.data[i].clickNum + "</a></i></div></div><div class=\"sviewr\">";
                        str += "</div></div></div>";
                        str += "</div>"
                    }
                    $("#newstitle").html(str);

                } else {
                    alert(res6.msg)
                }
            }, "json");
        }

        function newscont(id) {
            location.assign("newsContent.html?id=" + id);
        }

        //收藏
        function collect() {
            console.log($("#collect").prop("checked"))
            var id = location.search.split("=")[1];
            var userId = window.sessionStorage.getItem("userId");
            console.log(userId);
            console.log(id)
            if (userId == null) {
                alert("您还未登陆，请先登陆账号")
                location.assign("../user/user_login.html");
            } else {
                if ($("#collect").prop("checked") == true) {

                    $.post("../webmsg/collect", {userId: userId, Id: id}, function (res10) {
                        console.log(res10.data)
                        if (res10.code == 200) {
                            alert("收藏成功")
                            var n = document.getElementById("collectimg")
                            n.src = "../style/img/front/shoucang1.png"
                        } else {
                            alert(res10.msg)
                        }
                    }, "json");

                } else {
                    //取消收藏
                    $.get("../user/deleteCollect", {collectNewsId: id}, function (res) {
                        if (res.code === 500) {
                            alert(res.msg);
                        } else if (res.code === 202) {
                            alert("登录失效,请重新登录")
                        } else {
                            console.log(1)
                            var n = document.getElementById("collectimg")
                            n.src = "../style/img/front/shoucang.png"
                        }
                    })
                }

            }
        }

        function sendComment() {
            var id = location.search.split("=")[1];
            var userId = window.sessionStorage.getItem("userId");
            var comment = $("#addCommentId").val();
            if (userId == null) {
                alert("请先登录")
                location.assign("../user/user_login.html");
            } else {
                $.get("../comment/sendComment", {newsId: id, content: comment}, function (res) {
                    if (res.code===500||res.code===202||res.code===201){
                        alert(res.msg)
                    }else if(res.code===200){
                        alert(res.msg)
                        location.reload()
                    }
                })
            }
        }
    </script>
</head>
<body>
<div>
    <!-- 顶部 -->

    <!-- 内容区 -->
    <div id="main_box">
        <div class="left">
            <div class="left-col">
                <div class="nav">
                    <ul class="sf-menu sf-arrows" id="newstype">
                    </ul>
                </div>
            </div>
        </div>
        <!--中间区域-->
        <div class="middle">
            <!---轮播内容-->
            <div class="gslider">
                <!-- 图片滑动 -->
            </div>

            <!--文章容器  文章列表开始-->
            <div class="recent-content">
                <h2><span id="type"></span></h2>
                <div>
                    <div id="newstitle">
                    </div>
                    <div>
                        <input type="checkbox" name="collect" id="collect" onclick="collect()">收藏
                        <img id="collectimg" src="../style/img/front/shoucang.png" height="20" width="20">
                    </div>
                    <!--评论区-->
                    <div id="commentDiv">

                    </div>
                    <br>
                    <input type="text" id="addCommentId">
                    <input type="button" value="发送" onclick="sendComment()">
                </div>
            </div>
        </div>
        <div class="right">
            <div class="searchbox">
                <form id="searchform" method="get">
                    <input type="search" name="searchname" class="search-input" value="" placeholder="请输入关键词"
                           autocomplete="off">
                    <input type="button" class="search-submit" onclick="search()" value="搜索"></input>
                </form>
            </div>
            <!--广告图-->
            <div class="ali">
                <a href="" id="admsg3">

                </a>
            </div>
            <!--推荐文章-->
            <div class="sitebar-article">
                <h2><span>推荐文章</span></h2>
                <div class="sitebar-article-list">
                    <ul id="recommend">


                    </ul>
                </div>
            </div>

            <!--广告位-->
            <div class="ali">
                <a href="" id="admsg4">

                </a>
            </div>

            <!--点击最多的文章-->
            <div class="sitebar-article">
                <h2><span>点击最多的文章</span></h2>
                <div class="sitebar-article-list">
                    <ul id="click">
                    </ul>
                </div>
            </div>
        </div>
        <div style="clear: left;"></div>
        <!-- 底部友情链接,网站信息 -->
        <div class="main_bottom">
            <div class="main_bottom_link">
                <div class="main_bottom_link_title">友情链接</div>
                <div class="main_bottom_link_content" id="link">
                </div>
            </div>
            <div class="main_bottom_info" id="webmsg">
            </div>
        </div>
    </div>
</div>
</body>
</html>
